$(document).ready(function() {
	$(window).resize(function() {
		chart.resize();
	});

});
//************************************************************************************************************************/
//折线与柱状图
function chart_zx_and_zz(yarr_arr, msg_obj, axislabel, yyeDatamax) {

	//取得X轴的数组
	var xAxis_data = [];
	var series_data1 = [];
	var series_data2 = [];

	var series_data1_max = 0; //为了5格线也是拼了
	var series_data2_max = 0;

	//计算最大值
	mui.each(yarr_arr.data, function(index, item) {
		xAxis_data[index] = yarr_arr.data[index].name;
		series_data1[index] = yarr_arr.data[index].data[0];
		series_data2[index] = yarr_arr.data[index].data[1];
		(parseInt(series_data1[index]) > series_data1_max) ? series_data1_max = parseInt(series_data1[index]): series_data1_max = series_data1_max;
		(parseInt(series_data2[index]) > series_data2_max) ? series_data2_max = parseInt(series_data2[index]): series_data2_max = series_data2_max;
	});

	var tcolor = [];
	tcolor = fun_color(Object.keys(yarr_arr.data).length);

	//console.log(series_data2_max);

	//避免数据为0的情况
	(series_data1_max == 0) ? series_data1_max = 5: series_data1_max = series_data1_max;
	(series_data2_max == 0) ? series_data2_max = 5: series_data2_max = series_data2_max;

	//判断最大值
	series_data1_max = retMax(series_data1_max);
	series_data2_max = retMax(series_data2_max);

	//为了设定100%
	(yyeDatamax == 0) ? series_data2_max = series_data2_max: series_data2_max = yyeDatamax;

	// 因为是双y坐标轴, 刻度是按照最大-最小 来5等分，涉及到精度的问题，有可能会导致两边的轴不对齐
	// 因此，需要对最大值和最小值，做一个处理，向上和向下 来取一个恰好五等分的距离
	var minKll = 0,
		maxKll = series_data1_max,
		minYye = 0,
		maxYye = series_data2_max;

	// 为避免出现精度问题， 重新计算5等分值 (kllInterval, yyeInterval 是5等分值 )
	var kllInterval = Math.ceil((maxKll - minKll) / 5),
		yyeInterval = Math.ceil((maxYye - minYye) / 5);
	maxKll = minKll + kllInterval * 5;
	maxYye = minYye + yyeInterval * 5;

	// x轴数据
	var times = xAxis_data; //['00:00', '04:00', '08:00', '12:00', '16:00', '20:00', '24:00']; 

	// 客流量(柱图bar)
	var kllData = series_data1; //[220, 105, 250, 160, 320, 195, 408];
	// 营业额(曲线图 line)
	var yyeData = series_data2; //[950, 1050, 4000, 2900, 4050, 3000, 3800];

	//console.log(maxKll);
	//console.log(maxYye);

	//console.log(kllData);
	//console.log(yyeData);

	// 注意Y轴的name，用了全角空格做占位，因为属性里的对齐方式，达不到效果
	var option = {
		title: {
			text: yarr_arr.name,
			textStyle: {
				color: '#4D4D4D',
				fontSize: 15,
				height: 15,
				fontWeight: 400
			},
			left: 'center',
			top: 4,
			padding: 0,
		},
		grid: {
			top: 70,
			bottom: 55,
			left: 40,
			right: 40,
			border: '1px solid #F00'
		},
		tooltip: {
			trigger: 'axis',
			padding: 0, //在div中设置
			formatter: function(datas) {
				var sbxx = '<div class="tooltip_formatter">' + '时间' + ': ' + datas[0].name + '</div>';
				sbxx += '<div class="tooltip_formatter">' + datas[0].seriesName + ': ' + datas[0].value + '</div>';
				sbxx += '<div class="tooltip_formatter">' + datas[1].seriesName + ': ' + datas[1].value + '</div>';
				return sbxx;
			},
		},
		color: ['#4198FF', '#FF6A4C'],
		legend: {
			data: [yarr_arr.line[0], yarr_arr.line[1]],
			itemGap: 10,
			bottom: 5,
			left: 'center',
			textStyle: {
				fontSize: 10,
				color: '#808080',
				padding: [0, 10]
			},
			itemHeight: 5,
			itemWidth: 30,
			icon: 'img://beijing.png',
		},
		toolbox: {
			itemSize: 17,
			right: 5,
			top: 0,
			showTitle: false,
			feature: {
				myHelp: {
					title: '',
					icon: 'image://img//problem.png',
					onclick: function() {
						// 在此处编写点击事件
						time_img(msg_obj);
					}
				}
			}
		},
		xAxis: {
			type: 'category',
			data: times,
			splitLine: {
				show: false
			},
			axisTick: {
				show: false
			},
			axisLabel: {
				color: '#4D4D4D',
				fontSize: 10,
			},
			axisLine: {
				lineStyle: {
					color: '#808080',
					width: 0, //这里是为了突出显示加上的
				}
			}

		},
		yAxis: [{
				type: 'value',
				name: yarr_arr.line[0] + ' 　　　',
				min: minKll,
				max: maxKll,
				interval: kllInterval,
				nameGap: 15,
				nameTextStyle: {
					color: '#4D4D4D',
					fontSize: 10,
				},
				axisLabel: {
					color: '#4D4D4D',
					fontSize: 10
				},
				axisTick: {
					show: false
				},
				axisLine: {
					show: false
				}

			},
			{
				type: 'value',
				name: '　　　　' + yarr_arr.line[1],
				min: minYye,
				max: maxYye,
				interval: yyeInterval,
				nameGap: 15,
				nameTextStyle: {
					color: '#4D4D4D',
					fontSize: 10
				},
				axisLabel: {
					color: '#4D4D4D',
					fontSize: 10,
					formatter: '{value}' + axislabel,
				},
				axisTick: {
					show: false
				},
				axisLine: {
					show: false
				},
				splitLine: {
					show: false
				}

			},
		],
		series: [{
				type: 'bar',
				yAxisIndex: 0,
				name: yarr_arr.line[0],
				barWidth: 12,
				symbol: 'circle', //拐点样式
				itemStyle: {
					normal: {
						label: { //标签显示位置
							show: false,
							position: 'top' //insideTop 或者横向的 insideLeft

						},
						color: function(params) {
							var colorList = tcolor;
							return colorList[params.dataIndex]
						},
					},
				},
				data: kllData
			},
			{
				type: 'line',
				yAxisIndex: 1,
				name: yarr_arr.line[1],
				symbol: 'circle', //拐点样式
				label: {
					normal: {
						show: true,
						color: '#FF6A4C',
						fontSize: 10
					}
				},
				itemStyle: {
					normal: {
						label: { //标签显示位置
							show: true,
							position: 'top' //insideTop 或者横向的 insideLeft

						},
						color: "#ff6a4c",
						lineStyle: {
							type: 'solid',
							width: 1,
						},
					}
				},
				data: yyeData
			}

		]

	};
	return option;
}

function fun_color(num) {
	var t24 = [
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)'
	];

	var to = [];

	var t7 = [
		'rgba(65, 152, 255, 1)'
	];

	var t8 = [
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)'
	];

	var t9 = [
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)'
	];

	var t10 = [
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)'
	];

	var t11 = [
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)'
	];

	var t12 = [
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)'

	];
	var t13 = [
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)'
	];

	var t14 = [
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 0)',
		'rgba(65, 152, 255, 1)',
		'rgba(65, 152, 255, 1)'
	];

	//console.log(num);

	if(num == 25) {
		return t24;
	} else if(num <= 7) {
		return t7;
	} else {
		if(num == 8) {
			return t8;
		} else if(num == 9) {
			return t9;
		} else if(num == 10) {
			return t10;
		} else if(num == 11) {
			return t11;
		} else if(num == 12) {
			return t12;
		} else if(num == 13) {
			return t13;
		} else if(num == 14) {
			return t14;
		} else {
			return t24;
		}

	}
}